-- =============================================
-- Add constraint for table SAVINGBOOK
-- =============================================

USE SBM
GO

ALTER TABLE dbo.SAVINGBOOK
	ADD CONSTRAINT SB_DF_OD DEFAULT GetDate() FOR OpeningDate
GO

ALTER TABLE dbo.SAVINGBOOK
	ADD CONSTRAINT SB_DF_ISD DEFAULT GetDate() FOR InterestStartingDate
GO

ALTER TABLE dbo.SAVINGBOOK
	ADD CONSTRAINT SB_DF_AB DEFAULT 0 FOR AccountBalance
GO

ALTER TABLE dbo.SAVINGBOOK
	ADD CONSTRAINT SB_DF_SBS DEFAULT 1 FOR SBStatus
GO

-- =============================================
-- Add constraint for table SAVINGTYPE
-- =============================================

USE SBM
GO

ALTER TABLE dbo.SAVINGTYPE
	ADD CONSTRAINT ST_UNI_TN UNIQUE (TypeName)
GO

ALTER TABLE dbo.SAVINGTYPE
	ADD CONSTRAINT ST_CHK_IR CHECK(InterestRate>=0)
GO

ALTER TABLE dbo.SAVINGTYPE
	ADD CONSTRAINT ST_DF_IR DEFAULT 0 FOR InterestRate
GO

ALTER TABLE dbo.SAVINGTYPE
	ADD CONSTRAINT ST_DF_AS DEFAULT 1 FOR AllowSave
GO

ALTER TABLE dbo.SAVINGTYPE
	ADD CONSTRAINT ST_DF_AW DEFAULT 1 FOR AllowWithdraw
GO

ALTER TABLE dbo.SAVINGTYPE
	ADD CONSTRAINT ST_CHK_T CHECK(Term<>0)
GO

-- =============================================
-- Add constraint for table DEPOSIT
-- =============================================

USE SBM
GO

ALTER TABLE dbo.DEPOSIT
	ADD CONSTRAINT DO_DF_DD DEFAULT GetDate() FOR DepositingDate
GO

ALTER TABLE dbo.DEPOSIT
	ADD CONSTRAINT DO_CHK_AOM CHECK (AmountOfMoney >= 0)
GO

-- =============================================
-- Add constraint for table WITHDRAW
-- =============================================

USE SBM
GO

ALTER TABLE dbo.WITHDRAW
	ADD CONSTRAINT WO_DF_WD DEFAULT GetDate() FOR WithdrawingDate
GO

ALTER TABLE dbo.WITHDRAW
	ADD CONSTRAINT WO_CHK_AOM CHECK (AmountOfMoney >= 0)
GO